package com.jp.knowledge.view;

import android.content.Context;
import android.text.InputType;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by 528787067@qq.com on 2017/6/14.
 */

public class PayIntegralSelectView extends PaySelectView {
    public PayIntegralSelectView(Context context) {
        super(context);
    }

    public PayIntegralSelectView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PayIntegralSelectView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init() {
        super.init();
        ((TextView)moneyBtn1.getChildAt(0)).setText("10");
        ((TextView)moneyBtn1.getChildAt(1)).setText("币");
        ((TextView)moneyBtn5.getChildAt(0)).setText("50");
        ((TextView)moneyBtn5.getChildAt(1)).setText("币");
        ((TextView)moneyBtn8.getChildAt(0)).setText("80");
        ((TextView)moneyBtn8.getChildAt(1)).setText("币");
        ((TextView)moneyBtn10.getChildAt(0)).setText("100");
        ((TextView)moneyBtn10.getChildAt(1)).setText("币");
        ((TextView)moneyBtn50.getChildAt(0)).setText("500");
        ((TextView)moneyBtn50.getChildAt(1)).setText("币");
        ((TextView)moneyBtn99.getChildAt(0)).setText("1000");
        ((TextView)moneyBtn99.getChildAt(1)).setText("币");
        moneyInput.setHint("不能低于10币");
        moneyInput.setInputType(InputType.TYPE_CLASS_NUMBER);

        moneyBtn1.setTag(10);
        moneyBtn5.setTag(50);
        moneyBtn8.setTag(80);
        moneyBtn10.setTag(100);
        moneyBtn50.setTag(500);
        moneyBtn99.setTag(1000);
        moneyBtnOther.setTag(0);
    }

    @Override
    @Deprecated
    public int getSelectMoney() {
        return getSelectIntegral();
    }

    public int getSelectIntegral(){
        if(preSelectIcon == null)
            return -1;
        if(preSelectIcon == moneyBtnOther && moneyInput.getText().toString().trim().length() > 0)
            try {
                return Integer.parseInt(moneyInput.getText().toString());
            } catch (Exception e){
                return -1;
            }
        else if(preSelectIcon == moneyBtnOther)
            return -1;
        return (int)preSelectIcon.getTag();
    }
}
